<%@ page pageEncoding="UTF-8"%>
<%@ include file="../commons/head.jsp"%>
<style type="text/css">
	.button{width: 100px;height: 30px;margin:3px 20px 3px 0;padding-top: 3px;}
	*{font-size: 14px;}
	.th td{font-weight: 700;}
	/* label{margin: 0 10px 0 18px;font-weight: 500;height: 25px;line-height: 25px;} */
     .control-label{padding: 0;font-weight: bold;}
     .diaform{margin: 20px auto;}
     h3{border-bottom:1px solid #ddd;padding-bottom:5px;width: 98%;  }
     .datagrid-view{border-top:1px solid #ddd;margin-top: 8px;}
     .datagrid-pager{border-bottom:1px solid #ccc;}
     hr{margin:15px 0 13px 0 ;background-color: #ddd;height: 1px;border: 0; width: 120%;}
     .jianju{margin-left:15px; }
     .datagrid-htable{
     font-weight:bold;
	/* background-color: #148CCA; */
	}
	.demo_line_01{
    
    margin: 5px 0;
    font-size: 50px;
    line-height: 1px;
    text-align: center;
	}
	.demo_line_01 .line{
	display:inline-block;
	   width:47.8%;
	   height:1px;
	   background:#ddd;
	   vertical-align:middle;
	   margin-top:8px;
	}
	.container-fluid{
	padding-left: 15px;
	}
	.datagrid-ftable td div{
		font-size: larger;
	
	}
	#pulldown{
		margin-top: 20px;
	}
	
/* td.datagrid-header-over{
	background: #148CCA !important;
} */
</style>
<title>消息管理</title>
<style>
.datagrid-body {
height:320px !important;
}
.datagrid-view {
height:350px !important;
}

</style>
<script type="text/javascript">
	var isValid;
	var helpType;
	var data;
	var flag=0;
	var del=0;
	$(function(){
		$("#search").click(function(){
			var params = {
				msgTitle:$("#msg_title").val(),
				startTime:$("#createStartTime").datebox('getValue'),
				endTime:$("#createEndTime").datebox('getValue'),
			};

			$("#tt").datagrid('load',params);
		});
		
		$("#add").click(function(){
			flag=0;
			$("#fm").form('reset');
			$("#fmid").val("");
			$("#dlg-buttons").show();
			$("#dlg").dialog("open");
			$('.window-header').find('.panel-title').text('新增');
		});
		
		$("#detail").click(function(){
			var row = $('#tt').datagrid('getSelected');
			if(!row){
				$.messager.alert("请选择一行","请选择一行","error");
				return ;
			}
			var id = row.id;
			if (id==del) {
				$.messager.alert("请选择一行","请选择一行","error");
				return ;
			}
			
			$("#fm").form('load','/training1-web/noticeMsg/detail?id='+id);
			flag=1;
			$("#dlg-buttons").hide();
			$("#dlg").dialog("open");
			$('.window-header').find('.panel-title').text('查看');
		});
		
		$('#fm').form({
	    	url:'/training1-web/noticeMsg/save',
	    	onSubmit: function(){
				return $(this).form('validate');
	   		},
	    	success:function(data){
		    	if (flag==0) {
					$('#fm').form('reset');
				}
		    	data = eval("("+data+")");
				if(data.result==1){
					$.messager.alert("成功","成功","info",reload);
				}else{
					$.messager.alert("失败：",data.msg,"error");
				}
	    	}
		});
	});
	
	function saved(){
		var start= $("#publishStartTime").datebox('getValue');
		var end = $("#publishEndTime").datebox('getValue');
		var startTime = new Date(start);
        var endTime = new Date(end);
        if (startTime <= endTime) {
        	$('#fm').submit();
        }else{
        	$.messager.alert("失败","开始时间不能大于结束时间","error");
        }
	};

	function reload(){
		$("#tt").datagrid('reload');
	};

	function closeDlg(){
		$("#tt").datagrid('reload');
		$("#fm").clear();
		$('#dlg').dialog('close');
	};

	function getHelpType(value,row,index){
		for(var g in helpType){
			if(helpType[g].id==value){
				return helpType[g].name;
			}
		}
		return value;
	};

	function getIsValid(value,row,index){
		for(var g in isValid){
			if(isValid[g].id==value){
				return isValid[g].name;
			}
		}
		return value;
	}
	
	function rowStyle(index,row){
		if (index%2==0){     
	        return 'background-color:lightcyan;';     
	    }     
	}
	//鼠标悬停显示提示
	function showTips(value, row, index) {
		var content = '';
		if(value != null && value != '' || value == 0){
		    if(value.length>6 && strDateTime(value)){ //如果为时间
				value = value.substr(0,10);    	
		    }
		    content = '<span title="' + value + '" class="note" >' + value + '</span>';
		}
	    return content;
	}
	//日期格式化
	function gettime(val,row,index){
		if (val!=null) {
			  var s = val.substr(0,10);
		}
		return s;
	}

	//判断是否为时间格式 yyyy-MM-dd HH:mm:ss
	function strDateTime(str){
		var reg = /^(\d{1,4})(-|\/)(\d{1,2})\2(\d{1,2}) (\d{1,2}):(\d{1,2}):(\d{1,2})$/; 
		var r = str.match(reg); 
		if(r==null)return false; 
		var d= new Date(r[1], r[3]-1,r[4],r[5],r[6],r[7]); 
		return (d.getFullYear()==r[1]&&
		(d.getMonth()+1)==r[3]&&d.getDate()==r[4]&&d.getHours()==r[5]&&d.getMinutes()==r[6]&&d.getSeconds()==r[7
		]);
	}
</script>
</head>
<body>
<div class="jianju">
<h3>消息列表</h3>

<div id="tb" style="padding:5px;height:auto">
<div style="margin-bottom:5px">
	<a id="add" href="#" class="easyui-linkbutton button" iconCls="icon-add" plain="false">新增</a>
	<a id="detail" href="#" class="easyui-linkbutton button" iconCls="icon-search" plain="false">查看</a>
	<hr/>
</div>
<div>
	<label style="margin-left:0;">标题：</label><input id="msg_title" class="easyui-textbox" style="width:260px">
	<label style="margin-left:15px">发送时间：</label>
		<input id="createStartTime" type="text" class="easyui-datebox" style="width:110px" editable="false"/>
		&nbsp;~&nbsp;<input id="createEndTime" type="text" style="width:110px" class="easyui-datebox" editable="false" />
	
	
	<!-- 关键字：<input id="keyWord" class="easyui-textbox" style="width:100px"> -->
	
	<a id="search" href="#" class="easyui-linkbutton button" style="margin-left:15px;" iconCls="icon-search">查询</a>	
</div>
</div>

	<table id="tt" class="easyui-datagrid" 
		url="/training1-web/noticeMsg/list"
		title="" style="width:98%;minWidth:1000px;" 
		rownumbers="true" pagination="true"
		pageList="[10,20,30,40]" method="get"
		toolbar="#tb" singleSelect="true"
		fitColumns="true" idField="id" rowStyler="rowStyle">
		<thead>
			<tr style="background:#148CCA;">
				<th data-options="field:'msgTitle',formatter:getHelpType,formatter:showTips"style="width:34%">消息标题</th>
				<th data-options="field:'publishStartTimeStr', align:'center', formatter:gettime,formatter:showTips"style="width:35%">发送时间</th>
				<th data-options="field:'userName', align:'center',formatter:showTips"style="width:30%">发送者</th>
			</tr>
		</thead>
	</table>
</div>
	<!-- 输入画面弹层 -->
	<div id="dlg" class="easyui-dialog" style="width:500px;height:380px;padding:10px 20px"
		closed="true" buttons="#dlg-buttons" modal="true">
		<div class="ftitle"></div>
		<form id="fm" method="post" class="form-horizontal" role="form">
			<input type="hidden" name="id" id="fmid">
			<div id="username" class="fitem form-group">
				<label class="col-md-3 control-label">发送人：</label>
				<div class="col-md-4">
					<input name="userName" class="easyui-validatebox easyui-textbox" style="width:162px" value="${sessionScope.LOGININFO.loginName}" disabled>
				</div>
			</div>
			<div class="fitem form-group">
				<label class="col-md-3 control-label">消息类别：</label>
				<div class="col-md-4">
					 <!-- <input name="type" class="easyui-validatebox easyui-textbox" style="width:162px" value="群发" disabled> -->
					  <select id="type" name="type" class="easyui-combobox" style="width:162px" disabled >
						<option value="1" selected="selected" >全体</option>
					</select> 
				</div>
			</div>
			<div class="fitem form-group">
				<label class="col-md-3 control-label">标题：</label>
				<div class="col-md-4">
					<input id="msgTitle" name="msgTitle" type="text" class="easyui-validatebox easyui-textbox" style="width:300px" required="true" validType="length[1,50]"/>
				</div>
			</div>
			
			<div class="fitem form-group">
				<label class="col-md-3 control-label">发布有效时间：</label>
				<div class="col-sm-7">
					<input id="publishStartTime" name="publishStartTimeStr" type="text" class="easyui-datebox" style="width:110px" editable="false"/>
					&nbsp;~&nbsp;<input id="publishEndTime" name="publishEndTimeStr" type="text" style="width:110px" class="easyui-datebox" editable="false"/>
				</div>
			</div>
			
			<div class="fitem form-group">
				<label class="col-md-3 control-label">内容：</label>
				<div class="col-md-4">
					<textarea name="content" class="easyui-validatebox easyui-textarea" rows=5 style="width:300px" required="true" validType="length[1,200]"></textarea>
				</div>
			</div>
		</form>
	</div>
	
	<div id="dlg-buttons">
		<a href="#" class="easyui-linkbutton" iconCls="icon-ok" onclick="javascript:saved()" style="width:100px;height:30px" align="right">保存</a>
	</div>

</body>
</html>